#pragma once
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <variant>
#include <vector>

namespace MRMDS::Server
{
class DataBase
{
  public:
    using BasicValue = std::variant<int, float, double, std::string>;
    using SharePtr = std::shared_ptr<DataBase>;
    static SharePtr CreatSharePtr(std::vector<std::string> passwards) { return SharePtr(new DataBase(passwards)); }
    int Login(std::string name, std::string password);
    bool Logout(int id);
    std::map<int, std::string> GetInstanceList(int filter);
    std::map<int, std::map<int, BasicValue>> GetValues(std::vector<int> &ids, std::vector<int> &keys);
    bool SetValue(int id, std::map<int, BasicValue> &values);

  private:
    struct Instance
    {
        int id;
        std::string name;
        std::map<int, BasicValue> values;
    };
    DataBase(std::vector<std::string> passwards) : passwords(passwards) {}
    std::vector<std::string> passwords;
    std::mutex instanceMtx;
    std::map<int, Instance> instances;
    int id = 0;
};
} // namespace MRMDS::Server